import 'package:flutter/material.dart';
import '../helper/channelHelper.dart';

class DialogWidget {
  static Widget getDialog(
      BuildContext context, String title, String content, VoidCallback onYes) {
    return AlertDialog(
      title: Text(title),
      content: Text(content),
      actions: <Widget>[
        ElevatedButton(
          child: Text('确定'),
          onPressed: () {
            onYes();
            Navigator.of(context).pop();
          },
        ),
        ElevatedButton(
          child: Text('取消'),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
      ],
      backgroundColor: Colors.white,
      elevation: 20,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
    );
  }

  static Widget getAlert(BuildContext context, String title, String content) {
    return AlertDialog(
      title: Text(title),
      content: Text(content),
      actions: <Widget>[
        ElevatedButton(
          child: Text('确定'),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
      ],
      backgroundColor: Colors.white,
      elevation: 20,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
    );
  }

  static void ShowDelete(BuildContext context, String bz, VoidCallback onYes) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return DialogWidget.getDialog(
            context, "删除", "点击确定键将删除该条记录！  \r\n" + bz, onYes);
      },
    );
  }

  static void ShowUpload(BuildContext context, String bz, VoidCallback onYes) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return DialogWidget.getDialog(context, "提示", "点击确定将" + bz, onYes);
      },
    );
  }

  static void ShowToast(String content) async {
    await ChannelHelper.showToast(content);
  }
}
